package cz.muni.fi.pa165.business.service.utils;

import cz.muni.fi.pa165.api.dto.PickerDTO;
import cz.muni.fi.pa165.business.entity.Picker;
import java.util.ArrayList;
import java.util.List;

/**
 * Collection of transformation methods between Picker and PickerDTO objects
 *
 * @author Matej Cimbora
 */
public class PickerObjectTransformer {

    private PickerObjectTransformer() {
    }

    public static Picker pickerDTOToPicker(PickerDTO pickerDTO) {
        Picker picker = new Picker();
        picker.setId(pickerDTO.getId());
        picker.setNickName(pickerDTO.getNickName());
        picker.setFirstName(pickerDTO.getFirstName());
        picker.setLastName(pickerDTO.getLastName());
        picker.setPickerInfo(pickerDTO.getPickerInfo());
        picker.setPassword(pickerDTO.getPassword());
        if(pickerDTO.getUserRole() != null){
            picker.setUserRole(Picker.UserRole.valueOf(pickerDTO.getUserRole().toString()));
        }
        return picker;
    }

    public static PickerDTO pickerToPickerDTO(Picker picker) {
        if (picker == null) {
            return null;
        }
        PickerDTO pickerDTO = new PickerDTO();
        pickerDTO.setId(picker.getId());
        pickerDTO.setNickName(picker.getNickName());
        pickerDTO.setFirstName(picker.getFirstName());
        pickerDTO.setLastName(picker.getLastName());
        pickerDTO.setPickerInfo(picker.getPickerInfo());
        pickerDTO.setPassword(picker.getPassword());
        if(picker.getUserRole() != null){
            pickerDTO.setUserRole(PickerDTO.UserRole.valueOf(picker.getUserRole().toString()));
        }
        return pickerDTO;
    }

    public static List<PickerDTO> pickerListToPickerDTOList(List<Picker> pickerList) {
        List<PickerDTO> pickerDTOList = new ArrayList<>();

        for (Picker p : pickerList) {
            pickerDTOList.add(PickerObjectTransformer.pickerToPickerDTO(p));
        }

        return pickerDTOList;
    }
}
